package com.example.blogsystem.dao;

import com.example.blogsystem.model.Articleinfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2023-09-03
 * Time: 23:19
 */

@Mapper
public interface ArticleMapper {

    @Select("select * from articleinfo where uid = #{uid} order by id desc")
    List<Articleinfo> getArticleByUid(@Param("uid") int uid);

    @Delete("delete from articleinfo where id = #{id} and uid = #{uid}")
    int delByAidAndUid(@Param("id") Integer aid, int uid);

    @Insert("insert into articleinfo(title,content,uid) values (#{title},#{content},#{uid})")
    int add(Articleinfo articleinfo);

    @Select("select * from articleinfo where id = #{id} && uid = #{uid}")
    Articleinfo getByAidAndUid(@Param("id") int aid, @Param("uid") int uid);

    @Update("update articleinfo set title = #{title},content = #{content} where id = #{id} and uid = #{uid}")
    int update(Articleinfo articleinfo);

    @Select("select * from articleinfo where id = #{id}")
    Articleinfo getByAid(@Param("id") int aid);

    @Select("select count(*) from articleinfo where uid = #{uid}")
    int getCountByUid(@Param("uid") int uid);

    @Update("update articleinfo set rcount = rcount + 1 where id = #{id}")
    int readCountIncrement(@Param("id") int aid);

    @Select("select * from articleinfo order by id desc limit #{psize} offset #{offset}")
    List<Articleinfo> getArtByPage(@Param("psize") int psize, @Param("offset") int offset);

    @Select("select count(*) from articleinfo")
    int getAllArtCount();
}
